﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using VioletDevelopmentLaboratory.Net.Web;

public partial class vboard_membership_findpassword : VioletDevelopmentLaboratory.Net.Web.PageBase
{
	protected void Page_Init(object sender, EventArgs e)
	{
		Page.Header.Title = GetLocalResourceObject("Title").ToString();
	}

	protected void UserNameCheckButton_Click(Object sender, EventArgs e)
	{
		if (Page.IsValid)
		{
			MembershipUser user = Membership.GetUser(UserNameTextBox.Text);

			if (user == null)
			{
				VUtility.ShowMessagePanel(Page, VUtility.GetVWebGlobalResource("Membership_Do_FindPassword_UnknownUserName"), true);
				return;
			}

			UserNameCheckPanel.Visible = false;
			FindPasswordFormPanel.Visible = !UserNameCheckPanel.Visible;

			QuestionLiteral.Text = user.PasswordQuestion;
		}
	}

	protected void FindPasswordButton_Click(Object sender, EventArgs e)
	{
		if (Page.IsValid)
		{
			MembershipUser user = Membership.GetUser(UserNameTextBox.Text);

			if (user.IsLockedOut)
			{
				VUtility.ShowMessagePanel(Page, VUtility.GetVWebGlobalResource("Membership_Do_FindPassword_IsLockedout"), true);
				return;
			}

			try
			{
				String newPassword = user.ResetPassword(AnswerTextBox.Text);

				VUtility.ShowMessagePanel(Page, String.Format(VUtility.GetVWebGlobalResource("Membership_Do_FindPaddword_Success"),
					newPassword), true);

				AnswerTextBox.Text = "";
			}
			catch
			{
				VUtility.ShowMessagePanel(Page, String.Format(VUtility.GetVWebGlobalResource("Membership_Do_FindPaddword_Failure"),
					Membership.PasswordAttemptWindow, Membership.MaxInvalidPasswordAttempts), true);
			}
		}
	}
}
